package br.com.tmd.controlefinanceiro.util;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.stat.Statistics;


public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            
            sessionFactory = new Configuration().configure(
                    "br/com/tmd/controlefinanceiro/util/hibernate.cfg.xml").buildSessionFactory();
        } catch (HibernateException ex) {

            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static Statistics getStatistics() {
        if (!sessionFactory.getStatistics().isStatisticsEnabled()) {
            sessionFactory.getStatistics().setStatisticsEnabled(true);
        }
        return sessionFactory.getStatistics();
    }
}
